//This is the implementation of the IView Interface.
//Visualization master object
  function ViewModelContainer() {
	ViewModelContainer.prototype.controller = null;
	ViewModelContainer.prototype.filterModel = new ViewSearchCriteria();
	ViewModelContainer.prototype.resourcesModel = new ResourcesBasicContentViewModel();
	ViewModelContainer.prototype.navigatorButtonsModel = new NavigationButtonsViewModel();
	ViewModelContainer.prototype.additionalDataViewModel = new AdditionalDataViewModel();
	ViewModelContainer.prototype.fullDetailsViewModel = new FullDetailsViewModel();
	ViewModelContainer.prototype.self  = null;
}

//Implement the IView interface
ViewModelContainer.prototype = Object.create(IView.prototype);

//Initialize default values
//The View has a reference to the Controller, but only through the Interface (IController), not the actual implementation which could be interchangeable
ViewModelContainer.prototype.initialize = function(controller) {
	self=this;
	this.controller=controller;
	//Subscribe events to different user elements on the page
	this.filterModel.key.subscribe(function(newValue) {
		self.executeSearch();
	});
	this.filterModel.chosenSortOrder.subscribe(function(newValue) {
		self.executeSearch();
	});
	this.filterModel.chosenSortType.subscribe(function(newValue) {
		self.executeSearch();
	});
}
			
ViewModelContainer.prototype.onResourceClicked=function (res){
				self.controller.getAdditionalData(res.id);
			}
			
			
ViewModelContainer.prototype.onViewableClicked=function (res){
				if (res.viewable)
					self.controller.getFullDetails(res.id);
			}
			
ViewModelContainer.prototype.executeSearch=function (){
				var currentSearchCriteria = this.filterModel.getSearchCriteria()				
				this.controller.fetchData(currentSearchCriteria);
			}
			
ViewModelContainer.prototype.bindData = function(dataContentArray) {
	this.resourcesModel.updateResources(dataContentArray);	
}



ViewModelContainer.prototype.setNavigationButtonsAvailability = function (navigationButtonsModel) {
	this.navigatorButtonsModel.setNavigationButtonsAvailability(navigationButtonsModel);
};

ViewModelContainer.prototype.bindAdditionalDetailsData = function (content) {
	this.additionalDataViewModel.bindAdditionalDetailsData(content);
	$( "#detail-form" ).dialog( "open" );
	
};

ViewModelContainer.prototype.bindFullDetailsData = function (content) {
 this.fullDetailsViewModel.bindAdditionalDetailsData(content);
	$( "#full-details-form" ).dialog( "open" );
};


ViewModelContainer.prototype.moveNext = function () {
	self.controller.moveNext();
};
ViewModelContainer.prototype.movePrevious = function () {
	self.controller.movePrevious();
};







